package com.laurent.brewerhistory.common;

import com.laurent.brewerhistory.util.PatternUtil;

import org.json.JSONObject;

import java.io.Serializable;

public class Criteria implements Serializable {

	private static final long serialVersionUID = 947697264081887617L;

	public static String OP_EQ = " = ";
	public static String OP_NOT_EQ = " <> ";
	public static String OP_LIKE = " LIKE ";
	public static String OP_NOT_LIKE = " NOT LIKE ";
	public static String OP_CONTAINS = " CONTAINS ";
	public static String OP_GE = " >= ";
	public static String OP_LE = " <= ";
	public static String OP_IN = " IN ";
	public static String OP_IS_NULL = " IS NULL ";

	private String key;
	private String value;
	private String op;
	private JSONObject jsonvalue;

	public Criteria(String key, String value) {
		this(key, value, OP_EQ);
	}

	public Criteria(String key, String value, String op) {
		this.key = key;
		this.value = value;
		this.op = op;
	}

	public Criteria(String key, JSONObject value) {
		this.key = key;
		this.jsonvalue = value;
	}

	public String getKey() {
		return key;
	}

	public Object getValue() {
		return PatternUtil.isEmpty(value) ? jsonvalue : value;
	}

	public String getOp() {
		return op;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setOp(String op) {
		this.op = op;
	}
}
